<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   PHP爬虫：百万级别“知乎”用户数据爬取与分析  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/21617.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466459419: Accept with keywords: (title(0.333333333333):社区,用户,级别,数盟,爬虫,数据, topn(0.3):初始化,社区,程序运行,数盟,信息,数据分析,文件,用户名,结果,句柄,数据库,文章,数据,图片,函数,个人,方案,编程,用户,进程,核数,链接,编程语言,示例,程序,爬虫,列表,正则,时候,页面).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    PHP爬虫：百万级别“知乎”用户数据爬取与分析
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    PHP爬虫：百万级别“知乎”用户数据爬取与分析 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,70] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech/devl">
       编程语言
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/21617.html">
          PHP爬虫：百万级别“知乎”用户数据爬取与分析
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          1,734 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech/devl" rel="category tag">
          编程语言
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        这次抓取了110万的用户数据，数据分析结果如下：
       </p>
       <p>
        <img src="http://s5.51cto.com/wyfs02/M00/7A/0C/wKiom1ahr1yB164KAALXebQHEIo215.jpg"/>
       </p>
       <p>
        <strong>
         开发前的准备
        </strong>
       </p>
       <p>
        安装Linux系统（Ubuntu14.04），在VMWare虚拟机下安装一个Ubuntu；
       </p>
       <p>
        安装PHP5.6或以上版本；
       </p>
       <p>
        安装MySQL5.5或以上版本；
       </p>
       <p>
        安装curl、pcntl扩展。
       </p>
       <p>
        <strong>
         使用PHP的curl扩展抓取页面数据
        </strong>
       </p>
       <p>
        PHP的curl扩展是PHP支持的允许你与各种服务器使用各种类型的协议进行连接和通信的库。
       </p>
       <p>
        本程序是抓取知乎的用户数据，要能访问用户个人页面，需要用户登录后的才能访问。当我们在浏览器的页面中点击一个用户头像链接进入用户个人中心页面 的时候，之所以能够看到用户的信息，是因为在点击链接的时候，浏览器帮你将本地的cookie带上一齐提交到新的页面，所以你就能进入到用户的个人中心页 面。因此实现访问个人页面之前需要先获得用户的cookie信息，然后在每次curl请求的时候带上cookie信息。在获取cookie信息方面，我是 用了自己的cookie，在页面中可以看到自己的cookie信息：
       </p>
       <p>
        <img src="http://s2.51cto.com/wyfs02/M02/7A/0B/wKioL1ahr5qzsveOAACxjZ-8hfc872.jpg"/>
       </p>
       <p>
        一个个地复制，以”__utma=?;__utmb=?;”这样的形式组成一个cookie字符串。接下来就可以使用该cookie字符串来发送请求。
       </p>
       <p>
        <strong>
         初始的示例：
        </strong>
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686518f36d2237674805" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           PHP
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          $url = 'http://www.zhihu.com/people/mora-hu/about'; //此处mora-hu代表用户ID 
$ch = curl_init($url); //初始化会话 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_COOKIE, $this-&gt;config_arr['user_cookie']);  //设置请求COOKIE 
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  //将curl_exec()获取的信息以文件流的形式返回，而不是直接输出。 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  
$result = curl_exec($ch); 
return $result;  //抓取的结果
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686518f36d2237674805-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36d2237674805-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36d2237674805-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36d2237674805-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36d2237674805-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36d2237674805-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36d2237674805-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36d2237674805-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36d2237674805-9">
               9
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686518f36d2237674805-1">
               <span class="crayon-v">
                $url
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'http://www.zhihu.com/people/mora-hu/about'
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //此处mora-hu代表用户ID
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36d2237674805-2">
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_init
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $url
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //初始化会话
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36d2237674805-3">
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_HEADER
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36d2237674805-4">
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_COOKIE
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $this
               </span>
               <span class="crayon-o">
                -&gt;
               </span>
               <span class="crayon-i">
                config_arr
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'user_cookie'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //设置请求COOKIE
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36d2237674805-5">
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_USERAGENT
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $_SERVER
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'HTTP_USER_AGENT'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36d2237674805-6">
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_RETURNTRANSFER
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //将curl_exec()获取的信息以文件流的形式返回，而不是直接输出。
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36d2237674805-7">
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_FOLLOWLOCATION
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36d2237674805-8">
               <span class="crayon-v">
                $result
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_exec
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36d2237674805-9">
               <span class="crayon-k ">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $result
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //抓取的结果
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0225 seconds] -->
       <p>
        运行上面的代码可以获得mora-hu用户的个人中心页面。利用该结果再使用正则表达式对页面进行处理，就能获取到姓名，性别等所需要抓取的信息。
       </p>
       <p>
        <strong>
         图片防盗链
        </strong>
       </p>
       <p>
        在对返回结果进行正则处理后输出个人信息的时候，发现在页面中输出用户头像时无法打开。经过查阅资料得知，是因为知乎对图片做了防盗链处理。解决方案就是请求图片的时候在请求头里伪造一个referer。
       </p>
       <p>
        在使用正则表达式获取到图片的链接之后，再发一次请求，这时候带上图片请求的来源，说明该请求来自知乎网站的转发。具体例子如下：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686518f36e1148892514" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           PHP
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          function getImg($url, $u_id) 
{ 
    if (file_exists('./images/' . $u_id . ".jpg")) 
    { 
        return "images/$u_id" . '.jpg'; 
    } 
    if (empty($url)) 
    { 
        return ''; 
    } 
    $context_options = array(  
        'http' =&gt;  
        array( 
            'header' =&gt; "Referer:http://www.zhihu.com"//带上referer参数 
    ) 
); 
 
    $context = stream_context_create($context_options);  
    $img = file_get_contents('http:' . $url, FALSE, $context); 
    file_put_contents('./images/' . $u_id . ".jpg", $img); 
    return "images/$u_id" . '.jpg'; 
}
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-20">
               20
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36e1148892514-21">
               21
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36e1148892514-22">
               22
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686518f36e1148892514-1">
               <span class="crayon-t">
                function
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                getImg
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $url
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $u_id
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-2">
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                file_exists
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                './images/'
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $u_id
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                ".jpg"
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "images/$u_id"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '.jpg'
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-k ">
                empty
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $url
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                ''
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-11">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $context_options
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                array
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'http'
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-o">
                &gt;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-13">
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                array
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-14">
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'header'
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-o">
                &gt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "Referer:http://www.zhihu.com"
               </span>
               <span class="crayon-c">
                //带上referer参数
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-15">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-16">
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-17">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-18">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $context
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                stream_context_create
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $context_options
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-19">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $img
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                file_get_contents
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'http:'
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $url
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                FALSE
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $context
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-20">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                file_put_contents
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                './images/'
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $u_id
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                ".jpg"
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $img
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36e1148892514-21">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "images/$u_id"
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '.jpg'
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36e1148892514-22">
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0253 seconds] -->
       <p>
        <strong>
         爬取更多用户
        </strong>
       </p>
       <p>
        抓取了自己的个人信息后，就需要再访问用户的关注者和关注了的用户列表获取更多的用户信息。然后一层一层地访问。可以看到，在个人中心页面里，有两个链接如下：
       </p>
       <p>
        <img src="http://s3.51cto.com/wyfs02/M00/7A/0C/wKiom1ahr1zRtecJAABUdA7RL1c797.jpg"/>
       </p>
       <p>
        这里有两个链接，一个是关注了，另一个是关注者，以“关注了”的链接为例。用正则匹配去匹配到相应的链接，得到url之后用curl带上cookie再发一次请求。抓取到用户关注了的用于列表页之后，可以得到下面的页面：
       </p>
       <p>
        <img src="http://s3.51cto.com/wyfs02/M00/7A/0B/wKioL1ahr5rBxpfyAADTeATaL2E248.jpg"/>
       </p>
       <p>
        分析页面的html结构，因为只要得到用户的信息，所以只需要框住的这一块的div内容，用户名都在这里面。可以看到，用户关注了的页面的url是：
       </p>
       <p>
        <img src="http://s2.51cto.com/wyfs02/M01/7A/0C/wKiom1ahr1zS_WQIAAAiB4676tg416.jpg"/>
       </p>
       <p>
        不同的用户的这个url几乎是一样的，不同的地方就在于用户名那里。用正则匹配拿到用户名列表，一个一个地拼url，然后再逐个发请求（当然，一个 一个是比较慢的，下面有解决方案，这个稍后会说到）。进入到新用户的页面之后，再重复上面的步骤，就这样不断循环，直到达到你所要的数据量。
       </p>
       <p>
        <strong>
         Linux统计文件数量
        </strong>
       </p>
       <p>
        脚本跑了一段时间后，需要看看究竟获取了多少图片，当数据量比较大的时候，打开文件夹查看图片数量就有点慢。脚本是在Linux环境下运行的，因此可以使用Linux的命令来统计文件数量：
       </p>
       <p>
        ls -l | grep “^-” | wc -l
       </p>
       <p>
        其中，
        <code>
         ls -l 是长列表输出该目录下的文件信息（这里的文件可以是目录、链接、设备文件等）；
         <code>
          grep "^-" 过滤长列表输出信息，
          <code>
           "^-" 只保留一般文件，如果只保留目录是
           <code>
            "^d" ；
            <code>
             wc -l 是统计输出信息的行数。下面是一个运行示例：
            </code>
           </code>
          </code>
         </code>
        </code>
       </p>
       <p>
        <img src="http://s5.51cto.com/wyfs02/M01/7A/0B/wKioL1ahr5rCbJL7AAEQkHeTjbk191.jpg"/>
       </p>
       <p>
        <strong>
         插入MySQL时重复数据的处理
        </strong>
       </p>
       <p>
        程序运行了一段时间后，发现有很多用户的数据是重复的，因此需要在插入重复用户数据的时候做处理。处理方案如下：
       </p>
       <p>
        1）插入数据库之前检查数据是否已经存在数据库；
       </p>
       <p>
        2）添加唯一索引，插入时使用
        <code>
         INSERT INTO ... ON DUPLICATE KEY UPDATE...
        </code>
       </p>
       <p>
        3）添加唯一索引，插入时使用
        <code>
         INSERT INGNORE INTO...
        </code>
       </p>
       <p>
        4）添加唯一索引，插入时使用
        <code>
         REPLACE INTO...
        </code>
       </p>
       <p>
        第一种方案是最简单但也是效率最差的方案，因此不采取。二和四方案的执行结果是一样的，不同的是，在遇到相同的数据时， INSERT INTO … ON DUPLICATE KEY UPDATE 是直接更新的，而 REPLACE INTO 是先删除旧的数据然后插入新的，在这个过程中，还需要重新维护索引，所以速度慢。所以在二和四两者间选择了第二种方案。而第三种方案， INSERT INGNORE 会忽略执行INSERT语句出现的错误，不会忽略语法问题，但是忽略主键存在的情况。这样一来，使用 INSERT INGNORE 就更好了。最终，考虑到要在数据库中记录重复数据的条数，因此在程序中采用了第二种方案。
       </p>
       <p>
        <strong>
         使用curl_multi实现多线程抓取页面
        </strong>
       </p>
       <p>
        刚开始单进程而且单个curl去抓取数据，速度很慢，挂机爬了一个晚上只能抓到2W的数据，于是便想到能不能在进入新的用户页面发curl请求的时 候一次性请求多个用户，后来发现了curl_multi这个好东西。curl_multi这类函数可以实现同时请求多个url，而不是一个个请求，这类似 于linux系统中一个进程开多条线程执行的功能。下面是使用curl_multi实现多线程爬虫的示例：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686518f36ec162295447" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           PHP
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          $mh = curl_multi_init(); //返回一个新cURL批处理句柄 
for ($i = 0; $i &lt; $max_size; $i++) 
{ 
    $ch = curl_init();  //初始化单个cURL会话 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_URL, 'http://www.zhihu.com/people/' . $user_list[$i] . '/about'); 
    curl_setopt($ch, CURLOPT_COOKIE, self::$user_cookie); 
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36'); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    $requestMap[$i] = $ch; 
    curl_multi_add_handle($mh, $ch);  //向curl批处理会话中添加单独的curl句柄 
} 
 
$user_arr = array(); 
do { 
                //运行当前 cURL 句柄的子连接 
    while (($cme = curl_multi_exec($mh, $active)) == CURLM_CALL_MULTI_PERFORM); 
 
    if ($cme != CURLM_OK) {break;} 
                //获取当前解析的cURL的相关传输信息 
    while ($done = curl_multi_info_read($mh)) 
    { 
        $info = curl_getinfo($done['handle']); 
        $tmp_result = curl_multi_getcontent($done['handle']); 
        $error = curl_error($done['handle']); 
 
        $user_arr[] = array_values(getUserInfo($tmp_result)); 
 
        //保证同时有$max_size个请求在处理 
        if ($i &lt; sizeof($user_list) &amp;&amp; isset($user_list[$i]) &amp;&amp; $i &lt; count($user_list)) 
        { 
            $ch = curl_init(); 
            curl_setopt($ch, CURLOPT_HEADER, 0); 
            curl_setopt($ch, CURLOPT_URL, 'http://www.zhihu.com/people/' . $user_list[$i] . '/about'); 
            curl_setopt($ch, CURLOPT_COOKIE, self::$user_cookie); 
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36'); 
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
            $requestMap[$i] = $ch; 
            curl_multi_add_handle($mh, $ch); 
 
            $i++; 
        } 
 
        curl_multi_remove_handle($mh, $done['handle']); 
    } 
 
    if ($active) 
        curl_multi_select($mh, 10); 
} while ($active); 
 
curl_multi_close($mh); 
return $user_arr;
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-20">
               20
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-21">
               21
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-22">
               22
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-23">
               23
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-24">
               24
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-25">
               25
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-26">
               26
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-27">
               27
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-28">
               28
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-29">
               29
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-30">
               30
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-31">
               31
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-32">
               32
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-33">
               33
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-34">
               34
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-35">
               35
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-36">
               36
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-37">
               37
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-38">
               38
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-39">
               39
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-40">
               40
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-41">
               41
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-42">
               42
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-43">
               43
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-44">
               44
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-45">
               45
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-46">
               46
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-47">
               47
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-48">
               48
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-49">
               49
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-50">
               50
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-51">
               51
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-52">
               52
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36ec162295447-53">
               53
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36ec162295447-54">
               54
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686518f36ec162295447-1">
               <span class="crayon-v">
                $mh
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_multi_init
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //返回一个新cURL批处理句柄
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-2">
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $max_size
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-o">
                ++
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-3">
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_init
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //初始化单个cURL会话
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_HEADER
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_URL
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'http://www.zhihu.com/people/'
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $user_list
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '/about'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_COOKIE
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                self
               </span>
               <span class="crayon-o">
                ::
               </span>
               <span class="crayon-v">
                $user_cookie
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_USERAGENT
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_RETURNTRANSFER
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                true
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_FOLLOWLOCATION
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-11">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $requestMap
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_multi_add_handle
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $mh
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //向curl批处理会话中添加单独的curl句柄
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-13">
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-14">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-15">
               <span class="crayon-v">
                $user_arr
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                array
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-16">
               <span class="crayon-st">
                do
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-17">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //运行当前 cURL 句柄的子连接
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-18">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                while
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $cme
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_multi_exec
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $mh
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $active
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLM_CALL_MULTI_PERFORM
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-19">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-20">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $cme
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                !=
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLM_OK
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-st">
                break
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-21">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //获取当前解析的cURL的相关传输信息
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-22">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                while
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $done
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_multi_info_read
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $mh
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-23">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-24">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $info
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_getinfo
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $done
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'handle'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-25">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $tmp_result
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_multi_getcontent
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $done
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'handle'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-26">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $error
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_error
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $done
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'handle'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-27">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-28">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $user_arr
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                array_values
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                getUserInfo
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $tmp_result
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-29">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-30">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //保证同时有$max_size个请求在处理
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-31">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sizeof
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $user_list
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &amp;&amp;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                isset
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $user_list
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &amp;&amp;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                count
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $user_list
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-32">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-33">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_init
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-34">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_HEADER
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-35">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_URL
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'http://www.zhihu.com/people/'
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $user_list
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '/about'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-36">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_COOKIE
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                self
               </span>
               <span class="crayon-o">
                ::
               </span>
               <span class="crayon-v">
                $user_cookie
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-37">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_USERAGENT
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-38">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_RETURNTRANSFER
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                true
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-39">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_setopt
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                CURLOPT_FOLLOWLOCATION
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-40">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $requestMap
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-41">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_multi_add_handle
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $mh
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $ch
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-42">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-43">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-o">
                ++
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-44">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-45">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-46">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_multi_remove_handle
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $mh
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $done
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-s">
                'handle'
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-47">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-48">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-49">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $active
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-50">
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                curl_multi_select
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $mh
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                10
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-51">
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                while
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $active
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-52">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36ec162295447-53">
               <span class="crayon-e">
                curl_multi_close
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $mh
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36ec162295447-54">
               <span class="crayon-k ">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $user_arr
               </span>
               <span class="crayon-sy">
                ;
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.1107 seconds] -->
       <p>
        <strong>
         HTTP 429 Too Many Requests
        </strong>
       </p>
       <p>
        使用curl_multi函数可以同时发多个请求，但是在执行过程中使同时发200个请求的时候，发现很多请求无法返回了，即发现了丢包的情况。进 一步分析，使用 curl_getinfo 函数打印每个请求句柄信息，该函数返回一个包含HTTP response信息的关联数组，其中有一个字段是http_code，表示请求返回的HTTP状态码。看到有很多个请求的http_code都是 429，这个返回码的意思是发送太多请求了。我猜是知乎做了防爬虫的防护，于是我就拿其他的网站来做测试，发现一次性发200个请求时没问题的，证明了我 的猜测，知乎在这方面做了防护，即一次性的请求数量是有限制的。于是我不断地减少请求数量，发现在5的时候就没有丢包情况了。说明在这个程序里一次性最多 只能发5个请求，虽然不多，但这也是一次小提升了。
       </p>
       <p>
        <strong>
         使用Redis保存已经访问过的用户
        </strong>
       </p>
       <p>
        抓取用户的过程中，发现有些用户是已经访问过的，而且他的关注者和关注了的用户都已经获取过了，虽然在数据库的层面做了重复数据的处理，但是程序还 是会使用curl发请求，这样重复的发送请求就有很多重复的网络开销。还有一个就是待抓取的用户需要暂时保存在一个地方以便下一次执行，刚开始是放到数组 里面，后来发现要在程序里添加多进程，在多进程编程里，子进程会共享程序代码、函数库，但是进程使用的变量与其他进程所使用的截然不同。不同进程之间的变 量是分离的，不能被其他进程读取，所以是不能使用数组的。因此就想到了使用Redis缓存来保存已经处理好的用户以及待抓取的用户。这样每次执行完的时候 都把用户push到一个already_request_queue队列中，把待抓取的用户（即每个用户的关注者和关注了的用户列表）push到 request_queue里面，然后每次执行前都从request_queue里pop一个用户，然后判断是否在 already_request_queue里面，如果在，则进行下一个，否则就继续执行。
       </p>
       <p>
        <strong>
         在PHP中使用redis示例：
        </strong>
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686518f36fe541739828" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           PHP
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          &lt;php 
    $redis = new Redis(); 
    $redis-&gt;connect('127.0.0.1', '6379'); 
    $redis-&gt;set('tmp', 'value'); 
    if ($redis-&gt;exists('tmp')) 
    { 
        echo $redis-&gt;get('tmp') . "\n"; 
    }
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686518f36fe541739828-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36fe541739828-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36fe541739828-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36fe541739828-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36fe541739828-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36fe541739828-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686518f36fe541739828-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f36fe541739828-8">
               8
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686518f36fe541739828-1">
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-i">
                php
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36fe541739828-2">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $redis
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                new
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                Redis
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36fe541739828-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $redis
               </span>
               <span class="crayon-o">
                -&gt;
               </span>
               <span class="crayon-e">
                connect
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                '127.0.0.1'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                '6379'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36fe541739828-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $redis
               </span>
               <span class="crayon-o">
                -&gt;
               </span>
               <span class="crayon-e">
                set
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'tmp'
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                'value'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36fe541739828-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $redis
               </span>
               <span class="crayon-o">
                -&gt;
               </span>
               <span class="crayon-e">
                exists
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'tmp'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36fe541739828-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f36fe541739828-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                echo
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $redis
               </span>
               <span class="crayon-o">
                -&gt;
               </span>
               <span class="crayon-e">
                get
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                'tmp'
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "\n"
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f36fe541739828-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0169 seconds] -->
       <p>
        <strong>
         使用PHP的pcntl扩展实现多进程
        </strong>
       </p>
       <p>
        改用了curl_multi函数实现多线程抓取用户信息之后，程序运行了一个晚上，最终得到的数据有10W。还不能达到自己的理想目标，于是便继续优化，后来发现php里面有一个pcntl扩展可以实现多进程编程。下面是多编程编程的示例：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686518f370a692196273" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           PHP
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          //PHP多进程demo 
//fork10个进程 
for ($i = 0; $i &lt; 10; $i++) { 
    $pid = pcntl_fork(); 
    if ($pid == -1) { 
        echo "Could not fork!\n"; 
        exit(1); 
    } 
    if (!$pid) { 
        echo "child process $i running\n"; 
        //子进程执行完毕之后就退出，以免继续fork出新的子进程 
        exit($i); 
    } 
} 
 
//等待子进程执行完毕，避免出现僵尸进程 
while (pcntl_waitpid(0, $status) != -1) { 
    $status = pcntl_wexitstatus($status); 
    echo "Child $status completed\n"; 
}
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-17">
               17
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-18">
               18
              </div>
              <div class="crayon-num" data-line="crayon-57686518f370a692196273-19">
               19
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f370a692196273-20">
               20
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686518f370a692196273-1">
               <span class="crayon-c">
                //PHP多进程demo
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-2">
               <span class="crayon-c">
                //fork10个进程
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f370a692196273-3">
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                10
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-o">
                ++
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $pid
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                pcntl_fork
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f370a692196273-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $pid
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                echo
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "Could not fork!\n"
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f370a692196273-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                exit
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f370a692196273-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-o">
                !
               </span>
               <span class="crayon-v">
                $pid
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                echo
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "child process $i running\n"
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f370a692196273-11">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                //子进程执行完毕之后就退出，以免继续fork出新的子进程
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                exit
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f370a692196273-13">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-14">
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f370a692196273-15">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-16">
               <span class="crayon-c">
                //等待子进程执行完毕，避免出现僵尸进程
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f370a692196273-17">
               <span class="crayon-st">
                while
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                pcntl_waitpid
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $status
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                !=
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-18">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $status
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                pcntl_wexitstatus
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $status
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f370a692196273-19">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                echo
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "Child $status completed\n"
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f370a692196273-20">
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0364 seconds] -->
       <p>
        <strong>
         在Linux下查看系统的cpu信息
        </strong>
       </p>
       <p>
        实现了多进程编程之后，就想着多开几条进程不断地抓取用户的数据，后来开了8调进程跑了一个晚上后发现只能拿到20W的数据，没有多大的提升。于是 查阅资料发现，根据系统优化的CPU性能调优，程序的最大进程数不能随便给的，要根据CPU的核数和来给，最大进程数最好是cpu核数的2倍。因此需要查 看cpu的信息来看看cpu的核数。在Linux下查看cpu的信息的命令：
       </p>
       <ol class="dp-j">
        <li class="alt">
         cat /proc/cpuinfo
        </li>
       </ol>
       <p>
        结果如下：
       </p>
       <p>
        <img src="http://s4.51cto.com/wyfs02/M02/7A/0C/wKiom1ahr1yxzfoDAAOVA3DZDC0971.jpg"/>
       </p>
       <p>
        其中，model name表示cpu类型信息，cpu cores表示cpu核数。这里的核数是1，因为是在虚拟机下运行，分配到的cpu核数比较少，因此只能开2条进程。最终的结果是，用了一个周末就抓取了110万的用户数据。
       </p>
       <p>
        <strong>
         多进程编程中Redis和MySQL连接问题
        </strong>
       </p>
       <p>
        在多进程条件下，程序运行了一段时间后，发现数据不能插入到数据库，会报mysql too many connections的错误，redis也是如此。
       </p>
       <p>
        <strong>
         下面这段代码会执行失败：
        </strong>
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686518f3712605643030" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           PHP
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          &lt;php 
     for ($i = 0; $i &lt; 10; $i++) { 
          $pid = pcntl_fork(); 
          if ($pid == -1) { 
               echo "Could not fork!\n"; 
               exit(1); 
          } 
          if (!$pid) { 
               $redis = PRedis::getInstance(); 
               // do something     
               exit; 
          } 
     }
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686518f3712605643030-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3712605643030-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3712605643030-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3712605643030-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3712605643030-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3712605643030-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3712605643030-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3712605643030-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3712605643030-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3712605643030-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3712605643030-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3712605643030-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3712605643030-13">
               13
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686518f3712605643030-1">
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-e">
                php
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3712605643030-2">
               <span class="crayon-e">
               </span>
               <span class="crayon-st">
                for
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                10
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $i
               </span>
               <span class="crayon-o">
                ++
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3712605643030-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $pid
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                pcntl_fork
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3712605643030-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $pid
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                ==
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3712605643030-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                echo
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "Could not fork!\n"
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3712605643030-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                exit
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3712605643030-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3712605643030-8">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-o">
                !
               </span>
               <span class="crayon-v">
                $pid
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3712605643030-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $redis
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                PRedis::
               </span>
               <span class="crayon-e">
                getInstance
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3712605643030-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-c">
                // do something
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3712605643030-11">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                exit
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3712605643030-12">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3712605643030-13">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0171 seconds] -->
       <p>
        根本原因是在各个子进程创建时，就已经继承了父进程一份完全一样的拷贝。对象可以拷贝，但是已创建的连接不能被拷贝成多个，由此产生的结果，就是各个进程都使用同一个redis连接，各干各的事，最终产生莫名其妙的冲突。
       </p>
       <p>
        解决方法： &gt;程序不能完全保证在fork进程之前，父进程不会创建redis连接实例。因此，要解决这个问题只能靠子进程本身了。试想一下，如果在子进程中获 取的实例只与当前进程相关，那么这个问题就不存在了。于是解决方案就是稍微改造一下redis类实例化的静态方式，与当前进程ID绑定起来。
       </p>
       <p>
        <strong>
         改造后的代码如下：
        </strong>
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686518f371a761938914" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           PHP
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          &lt;php 
     public static function getInstance() { 
          static $instances = array(); 
          $key = getmypid();//获取当前进程ID 
          if ($empty($instances[$key])) { 
               $inctances[$key] = new self(); 
          } 
 
          return $instances[$key]; 
     }
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686518f371a761938914-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f371a761938914-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686518f371a761938914-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f371a761938914-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686518f371a761938914-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f371a761938914-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686518f371a761938914-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f371a761938914-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686518f371a761938914-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f371a761938914-10">
               10
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686518f371a761938914-1">
               <span class="crayon-o">
                &lt;
               </span>
               <span class="crayon-e">
                php
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f371a761938914-2">
               <span class="crayon-e">
               </span>
               <span class="crayon-m">
                public
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-m">
                static
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                function
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                getInstance
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f371a761938914-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-m">
                static
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $instances
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-t">
                array
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f371a761938914-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $key
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                getmypid
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-c">
                //获取当前进程ID
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f371a761938914-5">
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                if
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $empty
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $instances
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                $key
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f371a761938914-6">
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $inctances
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                $key
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                new
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-r">
                self
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f371a761938914-7">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f371a761938914-8">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f371a761938914-9">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $instances
               </span>
               <span class="crayon-sy">
                [
               </span>
               <span class="crayon-v">
                $key
               </span>
               <span class="crayon-sy">
                ]
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f371a761938914-10">
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                }
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0045 seconds] -->
       <p>
        <strong>
         PHP统计脚本执行时间
        </strong>
       </p>
       <p>
        因为想知道每个进程花费的时间是多少，因此写个函数统计脚本执行时间：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686518f3724672937270" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <span class="crayon-language">
           PHP
          </span>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          function microtime_float() 
{ 
     list($u_sec, $sec) = explode(' ', microtime()); 
     return (floatval($u_sec) + floatval($sec)); 
} 
 
$start_time = microtime_float(); 
 
//do something 
usleep(100); 
 
$end_time = microtime_float(); 
$total_time = $end_time - $start_time; 
 
$time_cost = sprintf("%.10f", $total_time); 
 
echo "program cost total " . $time_cost . "s\n";
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686518f3724672937270-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3724672937270-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3724672937270-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3724672937270-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3724672937270-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3724672937270-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3724672937270-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3724672937270-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3724672937270-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3724672937270-10">
               10
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3724672937270-11">
               11
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3724672937270-12">
               12
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3724672937270-13">
               13
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3724672937270-14">
               14
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3724672937270-15">
               15
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686518f3724672937270-16">
               16
              </div>
              <div class="crayon-num" data-line="crayon-57686518f3724672937270-17">
               17
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686518f3724672937270-1">
               <span class="crayon-t">
                function
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                microtime_float
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3724672937270-2">
               <span class="crayon-sy">
                {
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3724672937270-3">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                list
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $u_sec
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $sec
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                explode
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                ' '
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                microtime
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3724672937270-4">
               <span class="crayon-h">
               </span>
               <span class="crayon-k ">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-e">
                floatval
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $u_sec
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                floatval
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                $sec
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3724672937270-5">
               <span class="crayon-sy">
                }
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3724672937270-6">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3724672937270-7">
               <span class="crayon-v">
                $start_time
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                microtime_float
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3724672937270-8">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3724672937270-9">
               <span class="crayon-c">
                //do something
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3724672937270-10">
               <span class="crayon-e">
                usleep
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-cn">
                100
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3724672937270-11">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3724672937270-12">
               <span class="crayon-v">
                $end_time
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                microtime_float
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3724672937270-13">
               <span class="crayon-v">
                $total_time
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $end_time
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $start_time
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3724672937270-14">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3724672937270-15">
               <span class="crayon-v">
                $time_cost
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                sprintf
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-s">
                "%.10f"
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $total_time
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686518f3724672937270-16">
               <span class="crayon-h">
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686518f3724672937270-17">
               <span class="crayon-k ">
                echo
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "program cost total "
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                $time_cost
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "s\n"
               </span>
               <span class="crayon-sy">
                ;
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0306 seconds] -->
       <p>
        若文中有不正确的地方，望各位指出以便改正。
       </p>
       <p>
        代码托管地址：
        <a href="https://github.com/HectorHu/zhihuSpider" target="_blank">
         https://github.com/HectorHu/zhihuSpider
        </a>
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/24678.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/20140917125452915416-216x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24678.html" rel="bookmark" title="python3中的正则模块">
         python3中的正则模块
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24675.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/t015b337bd75d9ef893-161x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24675.html" rel="bookmark" title="注释是恶魔，请不要再写一行注释">
         注释是恶魔，请不要再写一行注释
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24660.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/u16130037972892789947fm21gp0-300x157.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/24660.html" rel="bookmark" title="如何从Github上轻松安装R包">
         如何从Github上轻松安装R包
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24654.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/06/df53fac99fc53ba5a90666abcca25e6d_b-267x200.png"/>
        </a>
        <a class="link" href="http://dataunion.org/24654.html" rel="bookmark" title="简单形象又有趣地说说强大的神经网络">
         简单形象又有趣地说说强大的神经网络
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <ul id="comment">
       <li id="comment-12927">
        <span>
         <p class="avatar" href="" target="_blank">
          <img src="https://secure.gravatar.com/avatar/92fa8be5c09739a36c5731be03054baa?s=86"/>
         </p>
        </span>
        <div class="mhcc">
         <address>
          小林子 - 
						2016/01/26
         </address>
         <p>
          Python相关的爬虫文章请看：
          <a href="http://dataunion.org/?s=python+%E7%88%AC%E8%99%AB" rel="nofollow" target="_blank">
           http://dataunion.org/?s=python+%E7%88%AC%E8%99%AB
          </a>
         </p>
        </div>
       </li>
       <!-- #comment-## -->
      </ul>
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F21617.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/21617.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/21617.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>